<script>
var options = '<option value="">请选择</option>';
for(var i=-30; i<= 30; i+= 0.25){
    options += '<option value="'+ i+'">'+  (i>0 ? '+'+formatnumber(i) : formatnumber(i)) +'</option>';
}
$('.ranges').html(options);

var options = '<option value="">请选择</option>';
for(var i=-8; i<= 8; i+= 0.25){
    options += '<option value="'+ i+'">'+  (i>0 ? '+'+formatnumber(i) : formatnumber(i)) +'</option>';
}
$('.ranges_1').html(options);
$('.ranges_1').select2();
$('.ranges').select2();

$("#formtable").validator({
    submit: function() {
        if(this.isFormValid()) {
            var that = $("#formtable");

            var sph = Number($('#sph').val());
            var sph1 = Number($('#sph1').val());
            var step_sph = Number($('#step_sph').val());

            var cyl = Number($('#cyl').val());
            var cyl1 = Number($('#cyl1').val());
            var step_cyl = Number($('#step_cyl').val());

            var x  =(sph1-sph)%step_sph;
            var y = (cyl1-cyl)%step_cyl;
            if(cyl1-cyl<0){
                layer.alert("柱镜所选区间范围无法计算");
                return false;
            }
            if(sph1-sph<0){
                layer.alert("球镜所选区间范围无法计算");
                return false;
            }
            if(x!=0){
                layer.alert("球镜所选区间范围无法计算");
                return false;
            }else if((cyl1!=0&&cyl!=0)&&(sph1==sph)) {
                layer.alert("球镜所选区间范围无法计算");
                return false;
            }
            if(y!=0){
                layer.alert("柱镜所选区间范围无法计算");
                return ;
            }else if((cyl1!=0&&cyl!=0)&&(cyl1==cyl)){
                layer.alert("柱镜所选区间范围无法计算");
                return false;
            }
            if(((sph1-sph)/step_sph)*((cyl1-cyl)/step_cyl)>500){
                layer.alert("区间选择范围过大，请缩小范围后再添加");
                return false;
            }
            $.ajax({
                url: location.href
                , type: 'post'
                , data: that.serialize()
                , dataType: 'json'
                , success: function (response) {
                    layer.msg(response.msg);
                    if (response.code === 0) {
                        setTimeout(function () {
                            if(typeof parent.dialogReback == 'function') {
                                parent.dialogReback();
                            }
                            parent.layer.closeAll('iframe');
                        }, 1000);
                    }
                }
                , error: function (error) {
                    layer.msg('数据提交失败！');
                }
            });
        }
        return false;
    }
});

</script>